#ifndef _XBASE_TABLET_H_
#define _XBASE_TABLET_H_

#include "XBaseSocket.h"

#include "XBaseCommandStruct.h"

#include <map>

class XBaseServer : public XBaseSocket
{
protected:
	TabletInfo _tablet_info;
	ServerAddress mTabletAddress;
	
public:
	XBaseServer();
	virtual ~XBaseServer();

	struct TabletInfo& tablet_info() { return _tablet_info; }
	struct ServerAddress& tabletAddress() { return mTabletAddress; }
	std::string tablet_name() { return (_tablet_info.tablet_name()); }
	std::string& row_from() { return _tablet_info.start_row(); };
	std::string& row_to() { return _tablet_info.end_row();};
	
	int execute(char* buffer, size_t buffer_size, size_t max_buffer_size);

protected:
	XDECL_LOGGER(logger);
};

class XBaseServerManager
{
public:
	// {table_name, XBaseServer}
	std::map<std::string, std::vector<XBaseServer> > _list;
	int mErrno;

	XBaseServer* get(const std::string& table_name, const std::string& row_key);
	void put(XBaseServer& tablet);
	void remove(XBaseServer& tablet);
	void remove(const std::string& table_name);
	void close();

	int errorno() { return mErrno; }

protected:
	XDECL_LOGGER(logger);
};

#endif

